home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / phpMyAdmin / libraries / tbl_info.inc.php < prev    next >
Encoding:
PHP Script  |  2007-12-20  |  3.5 KB  |  109 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  *
  5.  * @version $Id: tbl_info.inc.php 10679 2007-09-27 16:56:09Z lem9 $
  6.  */
  7.  
  8. /**
  9.  *
  10.  */
  11. require_once './libraries/Table.class.php';
  12.  
  13. /**
  14.  * extracts table properties from create statement
  15.  *
  16.  * @todo this should be recoded as functions,
  17.  * to avoid messing with global variables
  18.  */
  19.  
  20. /**
  21.  * requirements
  22.  */
  23. require_once './libraries/common.inc.php';
  24.  
  25. // Check parameters
  26. PMA_checkParameters(array('db', 'table'));
  27.  
  28. /**
  29.  * Defining global variables, in case this script is included by a function.
  30.  * This is necessary because this script can be included by libraries/header.inc.php.
  31.  */
  32. global $showtable, $tbl_is_view, $tbl_type, $show_comment, $tbl_collation,
  33.        $table_info_num_rows, $auto_increment;
  34.  
  35. /**
  36.  * Gets table informations
  37.  */
  38. // Seems we need to do this in MySQL 5.0.2,
  39. // otherwise error #1046, no database selected
  40. PMA_DBI_select_db($GLOBALS['db']);
  41.  
  42. // The 'show table' statement works correct since 3.23.03
  43. $table_info_result   = PMA_DBI_query(
  44.     'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\';',
  45.     null, PMA_DBI_QUERY_STORE);
  46.  
  47. // need this test because when we are creating a table, we get 0 rows
  48. // from the SHOW TABLE query
  49. // and we don't want to mess up the $tbl_type coming from the form
  50.  
  51. if ($table_info_result && PMA_DBI_num_rows($table_info_result) > 0) {
  52.     $showtable           = PMA_DBI_fetch_assoc($table_info_result);
  53.     PMA_DBI_free_result($table_info_result);
  54.     unset($table_info_result);
  55.  
  56.     if (!isset($showtable['Type']) && isset($showtable['Engine'])) {
  57.         $showtable['Type'] =& $showtable['Engine'];
  58.     }
  59.     if (PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])) {
  60.         $tbl_is_view     = true;
  61.         $tbl_type        = $GLOBALS['strView'];
  62.         $show_comment    = null;
  63.     } else {
  64.         $tbl_is_view     = false;
  65.         $tbl_type        = isset($showtable['Type'])
  66.             ? strtoupper($showtable['Type'])
  67.             : '';
  68.         // a new comment could be coming from tbl_operations.php
  69.         // and we want to show it in the header
  70.         if (isset($submitcomment) && isset($comment)) {
  71.             $show_comment = $comment;
  72.         } else {
  73.             $show_comment    = isset($showtable['Comment'])
  74.                 ? $showtable['Comment']
  75.                 : '';
  76.         }
  77.     }
  78.     $tbl_collation       = empty($showtable['Collation'])
  79.         ? ''
  80.         : $showtable['Collation'];
  81.  
  82.     if (null === $showtable['Rows']) {
  83.         $showtable['Rows']   = PMA_Table::countRecords($GLOBALS['db'],
  84.             $showtable['Name'], true, true);
  85.     }
  86.     $table_info_num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
  87.     $auto_increment      = isset($showtable['Auto_increment'])
  88.         ? $showtable['Auto_increment']
  89.         : '';
  90.  
  91.     $create_options      = isset($showtable['Create_options'])
  92.         ? explode(' ', $showtable['Create_options'])
  93.         : array();
  94.  
  95.     // export create options by its name as variables into gloabel namespace
  96.     // f.e. pack_keys=1 becomes available as $pack_keys with value of '1'
  97.     unset($pack_keys);
  98.     foreach ($create_options as $each_create_option) {
  99.         $each_create_option = explode('=', $each_create_option);
  100.         if (isset($each_create_option[1])) {
  101.             $$each_create_option[0]    = $each_create_option[1];
  102.         }
  103.     }
  104.     // we need explicit DEFAULT value here (different from '0')
  105.     $pack_keys = (!isset($pack_keys) || strlen($pack_keys) == 0) ? 'DEFAULT' : $pack_keys;
  106.     unset($create_options, $each_create_option);
  107. } // end if
  108. ?>
  109.